﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iNoteIt.Plugin
{
    public class PluginUnloadScope
    {
        public bool SupportUnoadScopeService<TService>() where TService : class
        {
            foreach (var generator in PluginService.Instance.UnloadScopeServiceGenerators)
            {
                if (generator.SupportUnloadScopeService<TService>())
                    return true;
            }

            return false;
        }

        public bool SupportUnoadScopeService(Type serviceType)
        {
            foreach (var generator in PluginService.Instance.UnloadScopeServiceGenerators)
            {
                if (generator.SupportUnloadScopeService(serviceType))
                    return true;
            }

            return false;
        }

        public TService GetService<TService>() where TService : class
        {
            foreach (var generator in PluginService.Instance.UnloadScopeServiceGenerators)
            {
                if (generator.SupportUnloadScopeService<TService>())
                {
                    return generator.GetUnloadScopeService<TService>();
                }
            }

            return null;
        }

        public object GetServie(Type serviceType)
        {
            foreach (var generator in PluginService.Instance.UnloadScopeServiceGenerators)
            {
                if (generator.SupportUnloadScopeService(serviceType))
                {
                    return generator.GetUnloadScopeService(serviceType);
                }
            }

            return null;
        }
    }
}
